﻿package com.mui.containers
{
    import com.mui.containers.globalVariable.*;
    import fl.core.*;
    import flash.display.*;

    public class GBox extends Container
    {
        public var layChildChanged:Boolean = false;
        protected var _numChildChanged:Boolean = false;
        private var _direction:String = "horizontal";
        private var _horizontalGap:Number = 0;
        private var _verticalGap:Number = 0;

        public function GBox()
        {
            this.tabChildren = false;
            return;
        }// end function

        override public function addChild(param1:DisplayObject) : DisplayObject
        {
            this._numChildChanged = true;
            return super.addChild(param1);
        }// end function

        override public function addChildAt(param1:DisplayObject, param2:int) : DisplayObject
        {
            this._numChildChanged = true;
            return super.addChildAt(param1, param2);
        }// end function

        override public function removeChild(param1:DisplayObject) : DisplayObject
        {
            this._numChildChanged = true;
            return super.removeChild(param1);
        }// end function

        override public function removeChildAt(param1:int) : DisplayObject
        {
            this._numChildChanged = true;
            return super.removeChildAt(param1);
        }// end function

        public function get direction() : String
        {
            return this._direction;
        }// end function

        public function set direction(param1:String) : void
        {
            if (this._direction == param1)
            {
                return;
            }
            this._direction = param1;
            invalidate(InvalidationType.ALL);
            return;
        }// end function

        public function get horizontalGap() : Number
        {
            return this._horizontalGap;
        }// end function

        public function set horizontalGap(param1:Number) : void
        {
            if (this._horizontalGap == param1)
            {
                return;
            }
            this._horizontalGap = param1;
            invalidate(InvalidationType.ALL);
            return;
        }// end function

        public function get verticalGap() : Number
        {
            return this._verticalGap;
        }// end function

        public function set verticalGap(param1:Number) : void
        {
            if (this._verticalGap == param1)
            {
                return;
            }
            this._verticalGap = param1;
            invalidate(InvalidationType.ALL);
            return;
        }// end function

        public function resetPosition2() : void
        {
            this.resetPosition();
            return;
        }// end function

        protected function resetPosition() : void
        {
            var _loc_1:int = 0;
            var _loc_4:DisplayObject = null;
            var _loc_2:int = 0;
            var _loc_3:* = this.numChildren;
            if (this.direction == GBoxDirection.VERTICAL)
            {
                _loc_1 = 0;
                while (_loc_1 < _loc_3)
                {
                    
                    _loc_4 = this.getChildAt(_loc_1);
                    _loc_4.x = 0;
                    _loc_4.y = _loc_2 + this.verticalGap;
                    if (_loc_4.visible)
                    {
                        _loc_2 = _loc_4.y + _loc_4.height;
                    }
                    _loc_1++;
                }
            }
            else if (this.direction == GBoxDirection.HORIZONTAL)
            {
                _loc_1 = 0;
                while (_loc_1 < _loc_3)
                {
                    
                    _loc_4 = this.getChildAt(_loc_1);
                    _loc_4.x = _loc_2 + this.horizontalGap;
                    _loc_4.y = 0;
                    if (_loc_4.visible)
                    {
                        _loc_2 = _loc_4.x + _loc_4.width;
                    }
                    _loc_1++;
                }
            }
            return;
        }// end function

        override protected function updateDisplayList() : void
        {
            if (this._numChildChanged || this.layChildChanged)
            {
                this._numChildChanged = false;
                this.layChildChanged = false;
                this.resetPosition();
            }
            super.updateDisplayList();
            return;
        }// end function

        override public function get height() : Number
        {
            var _loc_1:DisplayObject = null;
            if (this.direction == GBoxDirection.HORIZONTAL)
            {
                return super.height;
            }
            if (this.direction == GBoxDirection.VERTICAL)
            {
                if (this.numChildren > 0)
                {
                    _loc_1 = this.getChildAt((this.numChildren - 1));
                    return _loc_1.y + _loc_1.height;
                }
                return 0;
            }
            return super.height;
        }// end function

        override public function get width() : Number
        {
            var _loc_1:DisplayObject = null;
            if (this.direction == GBoxDirection.HORIZONTAL)
            {
                if (this.numChildren > 0)
                {
                    _loc_1 = this.getChildAt((this.numChildren - 1));
                    return _loc_1.x + _loc_1.width;
                }
                return 0;
            }
            else if (this.direction == GBoxDirection.VERTICAL)
            {
                return super.width;
            }
            return super.width;
        }// end function

        override public function dispose(param1:Boolean = true) : void
        {
            this._direction = GBoxDirection.HORIZONTAL;
            disposeChild(param1);
            this._horizontalGap = 0;
            super.dispose(param1);
            return;
        }// end function

    }
}
